package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduAssignmentSubmissionMapper;
import com.zenith.edu.po.domain.EduAssignmentSubmission;
import com.zenith.edu.po.dto.EduAssignmentSubmissionDTO;
import com.zenith.edu.po.vo.EduAssignmentSubmissionVO;
import com.zenith.edu.service.EduAssignmentSubmissionService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduAssignmentSubmissionServiceImpl extends ServiceImpl<EduAssignmentSubmissionMapper, EduAssignmentSubmission> implements EduAssignmentSubmissionService {
    
    @Override
    public EduAssignmentSubmissionVO createAssignmentSubmission(EduAssignmentSubmissionDTO dto) {
        EduAssignmentSubmission assignmentSubmission = new EduAssignmentSubmission();
        BeanUtils.copyProperties(dto, assignmentSubmission);
        this.save(assignmentSubmission);
        
        EduAssignmentSubmissionVO vo = new EduAssignmentSubmissionVO();
        BeanUtils.copyProperties(assignmentSubmission, vo);
        return vo;
    }
    
    @Override
    public EduAssignmentSubmissionVO getAssignmentSubmissionById(Long id) {
        EduAssignmentSubmission assignmentSubmission = this.getById(id);
        if (assignmentSubmission == null) {
            return null;
        }
        
        EduAssignmentSubmissionVO vo = new EduAssignmentSubmissionVO();
        BeanUtils.copyProperties(assignmentSubmission, vo);
        return vo;
    }
    
    @Override
    public EduAssignmentSubmissionVO updateAssignmentSubmission(EduAssignmentSubmissionDTO dto) {
        EduAssignmentSubmission assignmentSubmission = new EduAssignmentSubmission();
        BeanUtils.copyProperties(dto, assignmentSubmission);
        this.updateById(assignmentSubmission);
        
        EduAssignmentSubmissionVO vo = new EduAssignmentSubmissionVO();
        BeanUtils.copyProperties(assignmentSubmission, vo);
        return vo;
    }
    
    @Override
    public boolean deleteAssignmentSubmission(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduAssignmentSubmissionVO> getAssignmentSubmissionList() {
        List<EduAssignmentSubmission> assignmentSubmissionList = this.list();
        return assignmentSubmissionList.stream().map(assignmentSubmission -> {
            EduAssignmentSubmissionVO vo = new EduAssignmentSubmissionVO();
            BeanUtils.copyProperties(assignmentSubmission, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}